<template>
  <div>
    <p>首先会进行一次登录请求</p>
    <p>然后每十秒进行一次test请求</p>
  </div>
  <div>
    <p>运行日志：</p>
    <p v-for="(item, index) in log" :key="index">
      {{ item }}
    </p>
  </div>
</template>

<script>
// eslint-disable-next-line no-unused-vars
import {login, test} from "@/api/api";

export default {
  name: 'App',
  mounted() {
    login("admin", "123456").then(response => {
      const {access_token, refresh_token} = response.data.data
      localStorage.setItem("access_token", access_token)
      localStorage.setItem("refresh_token", refresh_token)
      this.LogPrint(`accessToken: ${access_token}`)
      this.LogPrint(`refresh_token: ${refresh_token}`)
    })
    setInterval(() => {
      test().then(response => {
        const {data} = response
        this.LogPrint(`状态码：${data.code}`)
      })
    }, 5000)
  },
  data() {
    return {
      log: []
    }
  },
  methods: {
    LogPrint(message) {
      this.log.push(message)
    }
  }
}
</script>

<style>
#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;
}
</style>
